#ifndef __LCD_H2
#define __LCD_H2	
#include "sys.h"	
#include "main.h"	
//==================================================================
enum LCD_INTERFACE{MCU16,SPI4Line,MCU8,MCUH8,SPI3Line,SPI3Line2,SPI4Line_CS_D8};
typedef struct _LCD_CONFIG{
	int col;
	int row;
	int col_pre;
	int row_pre;
	int delay_time;
	u8 is_commdata16;
	enum LCD_INTERFACE lcd_interface;
	u32 pic_bytes;
}LCD_CONFIG;
//==================================================================
///*LCD-MCU�˿ڶ���*/
//==================================================================
#define	LCD_RS_SET		GPIOA->BSRR=1<<4    //命令/数据   	PA4	   
#define	LCD_WR_SET		GPIOB->BSRR=1<<8    //写数据		PB8
#define	LCD_RD_SET		GPIOB->BSRR=1<<9    //读数据		PB9
#define	LCD_RST_SET		GPIOB->BSRR=1<<7    //复位			PB7
							    
#define	LCD_RS_CLR		GPIOA->BRR=1<<4     //命令/数据  	PA4	   
#define	LCD_WR_CLR		GPIOB->BRR=1<<8     //写数据		PB8
#define	LCD_RD_CLR		GPIOB->BRR=1<<9     //读数据		PB9
#define	LCD_RST_CLR		GPIOB->BRR=1<<7     //复位			PB7

//IO SPI
#define	LCD_SPI_SCL_SET		GPIOB->BSRR=1<<8    //SPI_SCL   PB8
#define	LCD_SPI_SDA_SET		GPIOB->BSRR=1<<9    //SPI_SDA   PB9
#define	LCD_SPI_SDA2_SET	GPIOB->BSRR=1<<7    //SPI_SDA2  PB7
 
#define	LCD_SPI_SCL_CLR		GPIOB->BRR=1<<8     //SPI_SCL
#define	LCD_SPI_SDA_CLR		GPIOB->BRR=1<<9     //SPI_SDA
#define	LCD_SPI_SDA2_CLR	GPIOB->BRR=1<<7     //SPI_SDA2

#define DATAOUT(x) 		GPIOB->ODR=x; 		//数据输出  B
#define DATAIN   		GPIOB->IDR;   		//数据输入

#define	LCD_PD_SET  	GPIOD->BSRR=1<<2    //  	PD2
#define	LCD_PD_CLR      GPIOD->BRR=1<<2 

#define	LCD_CS_SET  	CS_SET()    //片选端口  	PB6
#define	LCD_CS_CLR  	CS_CLR()    //片选端口  	PB6

//#define DATAOUT(x) 		GPIOD->ODR=2; 		//�������  LED PD2

#define	TP_CS_CLR       GPIOA->BRR=1<<15 
#define	TP_PENIRQ_CLR   GPIOA->BRR=1<<8 
#define	TP_DOUT_CLR     GPIOC->BRR=1<<11 
#define	TP_DIN_CLR      GPIOC->BRR=1<<10 
//#define	TP_DCLK_CLR     GPIOA->BRR=1<<14 
#define	TP_DCLK_CLR     GPIOA->BRR=1<<2 

#define	TP_CS_SET        GPIOA->BSRR=1<<15 
#define	TP_PENIRQ_SET    GPIOA->BSRR=1<<8 
#define	TP_DOUT_SET      GPIOC->BSRR=1<<11 
#define	TP_DIN_SET       GPIOC->BSRR=1<<10 
//#define	TP_DCLK_SET      GPIOA->BSRR=1<<14 
#define	TP_DCLK_SET      GPIOA->BSRR=1<<2 
#define PEN_IRQ  GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_8)
#define DOUT     GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_11) 
#define LCD_SPI_SDO    GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_9) 
//==================================================================
///*��������*/
//==================================================================
#define ENTER    GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2) //ENTER����
#define KEY_STEP  GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_1)	//STEP����
#define KEY_UP  GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_0)	//UP����
//==================================================================
///*������ɫ*/
//==================================================================
#define WHITE       0xFFFF
#define BLACK      	0x0000	  
#define BLUE       	0x001F 
#define BRED        0XF81F
#define GRED 			 	0XFFE0
#define GBLUE			 	0X07FF
#define RED         0xF800
#define MAGENTA     0xF81F
#define GREEN       0x07E0
#define CYAN        0x7FFF
#define YELLOW      0xFFE0
#define BROWN 			0XBC40 //��ɫ
#define BRRED 			0XFC07 //�غ�ɫ
#define GRAY  			0X8430 //��ɫ
#define GRAY25      0xADB5
//GUI��ɫ
#define DARKBLUE      	 0X01CF	//����ɫ
#define LIGHTBLUE      	 0X7D7C	//ǳ��ɫ  
#define GRAYBLUE       	 0X5458 //����ɫ
//������ɫΪPANEL����ɫ 
 
#define LIGHTGREEN     	0X841F //ǳ��ɫ
//#define LIGHTGRAY     0XEF5B //ǳ��ɫ(PANNEL)
#define LGRAY 			 		0XC618 //ǳ��ɫ(PANNEL),���屳��ɫ

#define LGRAYBLUE      	0XA651 //ǳ����ɫ(�м����ɫ)
#define LBBLUE          0X2B12 //ǳ����ɫ(ѡ����Ŀ�ķ�ɫ)

#define X_min 0x0043		 //TP���Է�Χ��������
#define X_max 0x07AE
#define Y_min 0x00A1
#define Y_max 0x0759
//==================================================================
extern u16 BACK_COLOR, POINT_COLOR ;  
void LCD_CONFIG_INIT(void);
void LCD_Init(void);
void LCD_IC_Init(void);
void LCD_WR_REG(u16 data);
void LCD_WR_DATA(u16 data);
void SendData(unsigned int color);
void DispColor(unsigned int color);

void BlockWrite(unsigned int Xstart,unsigned int Xend,unsigned int Ystart,unsigned int Yend);
void LCD_GPIOInit(void);

void WriteOneDot(unsigned int color);
void WriteDispData(unsigned int color1,unsigned int color2);
void DispFrame(void);
void DispBand(void);
void DispGrayHor16(void);
void DispGrayHor32(void);
extern void TP_DrawLine(void);
void DrawGird(unsigned int color);
void PutPixel(unsigned int x,unsigned int y,unsigned int color);
void DispStr(unsigned char *str,unsigned int Xstart,unsigned int Ystart,unsigned int TextColor,unsigned int BackColor);
void DispInt(unsigned int i,unsigned int Xstart,unsigned int Ystart,unsigned int TextColor,unsigned int BackColor);
void StopDelay(unsigned int sdly);
void LCD_SetCursor(unsigned short Xpos, unsigned short Ypos);
void LCD_Fast_DrawPoint(unsigned short x,unsigned short y,unsigned short color);
void  LCD_DispChars_24a(/*����X*/unsigned short Char_X,/*����Y*/unsigned short Char_Y,/*��ʾ����*/char hz[],/*��ʾ��ɫ*/uint16_t Char_Color,/*��ʾ��ʽ*/u8 XY_Mod );
//void LCD_ShowChar(uint16_t x,uint16_t y,uint16_t fc, uint16_t bc, uint8_t num,uint8_t size,uint8_t mode);
void LCD_ShowString(u16 x,u16 y,u16 width,u16 height,u8 size,u8 *p);
void LCD_DrawRectangle(u16 x1, u16 y1, u16 x2, u16 y2);
void LCD_DrawLine(u16 x1, u16 y1, u16 x2, u16 y2);
void LCD_DrawPoint(u16 x,u16 y);
//void LCD_ShowChar1(uint16_t x,uint16_t y,uint16_t fc, uint16_t bc, uint8_t num,uint8_t size,uint8_t mode);
void LCD_ShowCharaa(uint16_t x,uint16_t y,uint16_t fc, uint16_t bc, uint8_t num,uint8_t size,uint8_t mode);
void LCD_ShowCharqq(uint16_t x,uint16_t y,uint16_t fc, uint16_t bc, uint8_t num,uint8_t size,uint8_t mode);
void Show_Str(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str,uint8_t size,uint8_t mode);
//void LCD_ShowCharaa(u16 x,u16 y,u8 num,u8 size,u8 mode);
void LCD_ShowChar(u16 x,u16 y,u8 num,u8 size,u8 mode);
void DispColor_9bit_window(unsigned char r,unsigned char g,unsigned char b);
void DispBand_9b(void);	 
void DispFrame_9b(void);
void DispGrayHor16_9b(void); 
void DispChess(u8 div);
void TEST_STAND_9b(void);
#endif
